package br.com.eduquiz.entity;

import java.io.Serializable;
import java.util.Calendar;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;

import org.hibernate.validator.Length;
import org.hibernate.validator.Pattern;
import org.jboss.seam.annotations.Name;

@Entity
@Name("pessoa")
@Inheritance(strategy=InheritanceType.JOINED)
public class Pessoa implements Serializable {

	private static final long serialVersionUID = -2380241923009760377L;
	
	public enum Status { Ativo, Inativo }

	@Id
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	private Long id;
	
	@Length(max=255, min=2)
	private String nome;
	
	@Temporal(TemporalType.TIMESTAMP)
	private Calendar dataCadastro;
	
	/**
	 * O email é utilizado no login do sistema
	 */
	@Pattern(regex="[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}", message="E-mail inválido")
	@Length(min=8, max=255)
	@Column(unique=true, nullable=false)
	private String email;
	
	@Length(min=8, max=255)
	private String senha;
	
	@Enumerated(EnumType.STRING)
	private Status status = Pessoa.Status.Ativo;
	
	
	@Transient
	private String confirmarSenha;
	
	@ManyToMany
	@JoinTable(
			joinColumns=@JoinColumn(name="pessoa_id"),
			inverseJoinColumns=@JoinColumn(name="role_id")
			)
	private List<Role> role;

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getNome() {
		return nome;
	}

	public void setNome(String nome) {
		this.nome = nome;
	}

	public Calendar getDataCadastro() {
		return dataCadastro;
	}

	public void setDataCadastro(Calendar dataCadastro) {
		this.dataCadastro = dataCadastro;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String getSenha() {
		return senha;
	}

	public void setSenha(String senha) {
		this.senha = senha;
	}

	public void setStatus(Status status) {
		this.status = status;
	}

	public Status getStatus() {
		return status;
	}

	public void setConfirmarSenha(String confirmarSenha) {
		this.confirmarSenha = confirmarSenha;
	}

	public String getConfirmarSenha() {
		return confirmarSenha;
	}

	public void setRole(List<Role> role) {
		this.role = role;
	}

	public List<Role> getRole() {
		return role;
	}
}
